<?php

namespace app\controller\admin\info;

use app\BaseController;
use app\common\repositories\info\InfoRepository;
use app\common\repositories\info\InfoRepository as repository;
use app\common\repositories\info\QuestionRepository;
use app\common\repositories\lawyer\LawyerRepository;
use app\common\repositories\member\MemberSettingRepository;
use think\App;
use think\exception\ValidateException;

class Info extends BaseController
{
    protected repository $repository;

    public function __construct(App $app, repository $repository)
    {
        parent::__construct($app);
        $this->repository = $repository;
    }


    public function lst()
    {
        [$page,$limit] = $this->request->page();
        $where = $this->request->params(['status','start_time','end_time','city_id','order_type','nickname','phone']);

        if($where['order_type'] === 0){
            $where['type'] = 0;
        }else if($where['order_type'] == 7){
            $where['type'] = 7;
        }else if($where['order_type'] == 1){
            $where['type'] = [1,2,3,4,5,6];
        }

        unset($where['order_type']);

        return success($this->repository->getAdminLst($where,$page,$limit));
    }


    public function status($id)
    {
        $info = app()->make(InfoRepository::class)->get($id);
        if(!$info || !$info->is_paid){
            throw new ValidateException('订单不存在');
        }

        if($info->status == -1 || $info->status == 3 || !in_array(input('status',''),[2,3])){
            throw new ValidateException('订单状态有误');
        }

        $this->repository->setInfoStatus($id,input('status'));
        return success('修改状态成功');
    }


    public function getQuestionLst($id)
    {
        return success(app()->make(QuestionRepository::class)->detail($id));
    }


    



}